// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Text;	

namespace SoapTrace.Core.Communication
{
	/// <summary>
	/// A soap request message.
	/// </summary>
	public class SoapRequest : SoapMessage
	{
		/// <summary>
		/// The soap request's Http header.
		/// </summary>
		private SoapRequestHeader m_SoapHeader = new SoapRequestHeader( );


		/// <summary>
		/// Creates a new instance of the <see cref="SoapRequest"/> clas.
		/// </summary>
		public SoapRequest( )
		{
		}

		/// <summary>
		/// Gets the soap request's Http header.
		/// </summary>
		/// <returns></returns>
		protected override SoapHeader GetSoapHeader( )
		{
			return m_SoapHeader;
		}

		/// <summary>
		/// Gets the web service name and operation of the soap request in the
		/// form "ServiceName.OperationName".
		/// </summary>
		public string WebService
		{
			get
			{
				return SoapRequest.GetShortUri( m_SoapHeader.RequestUri );
			}
		}

		/// <summary>
		/// Gets the request Uri.
		/// </summary>
		public string Uri
		{
			get
			{
				return m_SoapHeader.RequestUri;
			}
		}

		/// <summary>
		/// Gets the last part of the uri used to call this soap request.
		/// </summary>
		/// <param name="uri">The full uri used to call this soap request.</param>
		/// <returns>The last part of the uri used to call this soap request.</returns>
		private static string GetShortUri( string uri )
		{
			string ShortUri = uri;

			int SlashIndex = uri.LastIndexOf( "/" );

			if( SlashIndex != -1 )
			{
				ShortUri = uri.Substring( SlashIndex + 1 );

				int StopIndex = ShortUri.LastIndexOf( "." );

				if( StopIndex != - 1 )
				{
					ShortUri = ShortUri.Remove( StopIndex, ShortUri.Length - StopIndex );
				}
			}

			return ShortUri;
		}

	}
}
